package com.yiper.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;

import java.io.IOException;
import java.util.Properties;

public class EnvUtils extends PropertySourcesPlaceholderConfigurer {
    private static Logger logger = LoggerFactory.getLogger(EnvUtils.class);
    private static Properties prop;

    public static String getProperty(String key) {
        return prop.getProperty(key);
    }

    public void init() throws IOException {
        try {
            if(prop == null){//即使多次实例化,只合并一次
                prop = super.mergeProperties();
            }
        } catch (IOException e) {
            logger.error("load properties error", e);
            throw new IOException("load properties error");
        }
    }
}